package com.snowRemovingUser.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.snowRemovingUser.domain.TOperation;
import com.snowRemovingUser.service.ITOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志Controller
 * 
 * @author liguang
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/snowRemoving/operation")
public class TOperationController extends BaseController
{
    @Autowired
    private ITOperationService tOperationService;

    /**
     * 查询操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:operation:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOperation tOperation)
    {
        startPage();
        List<TOperation> list = tOperationService.selectTOperationList(tOperation);
        return getDataTable(list);
    }

    /**
     * 导出操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:operation:export')")
    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TOperation tOperation)
    {
        List<TOperation> list = tOperationService.selectTOperationList(tOperation);
        ExcelUtil<TOperation> util = new ExcelUtil<TOperation>(TOperation.class);
        util.exportExcel(response, list, "操作日志数据");
    }

    /**
     * 获取操作日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:operation:query')")
    @GetMapping(value = "/{operId}")
    public AjaxResult getInfo(@PathVariable("operId") Long operId)
    {
        return success(tOperationService.selectTOperationByOperId(operId));
    }

    /**
     * 新增操作日志
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:operation:add')")
    @Log(title = "操作日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TOperation tOperation)
    {
        return toAjax(tOperationService.insertTOperation(tOperation));
    }

    /**
     * 修改操作日志
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:operation:edit')")
    @Log(title = "操作日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOperation tOperation)
    {
        return toAjax(tOperationService.updateTOperation(tOperation));
    }

    /**
     * 删除操作日志
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:operation:remove')")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(tOperationService.deleteTOperationByOperIds(operIds));
    }
}
